<template>
  <div :class="['component', 'simple_form', expand ? 'expand' : '']">
    <el-form ref="_simpleForm" v-bind="proxy.$attrs" label-width="120px">
      <template v-for="(value, name) in proxy.$slots" #[name]>
        <slot :name="name"></slot>
      </template>
    </el-form>
    <p v-if="keyCount > 4" class="sm_bottom">
      <i :class="['iconfont', expand ? 'hw-solid_arrowup' : 'hw-solid_arrowdown']" @click="expandRow"></i>
    </p>
  </div>
</template>

<script lang="ts" setup>
const expand = ref(false)
const keyCount = ref(0)
const _simpleForm = ref()
const { proxy }: any = getCurrentInstance()

const expandRow = () => {
  expand.value = !expand.value
}

onMounted(() => {
  keyCount.value = (Object.keys(proxy.$attrs.model || {})).length
  for (const [key, value] of Object.entries(_simpleForm.value)) {
    if(key) proxy[key] = value
  }
})
</script>

<style lang="less" scoped>
.simple_form {
  width: 100%;
  padding: 8px 0;
  :deep(.el-form) {
    width: 100%;
    display: flex;
    flex-flow: row wrap;
    justify-content: flex-start;
    .el-form-item {
      width: 20% !important;
      margin: 5px 2.5%;
      .el-input {
        width: 100%;
      }
      .el-select {
        width: 100%;
      }
    }
    .el-form-item:nth-child(n + 5) {
      display: none;
    }
  }
  .sm_bottom {
    height: 10px;
    line-height: 10px;
    width: 100%;
    text-align: center;
    i {
      display: inline-block;
      font-size: 10px;
    }
    i:hover, i:focus {
      color: #333;
      transform: scale(1.2);
    }
  }
}
.simple_form.expand {
  :deep(.el-form) {
    .el-form-item:nth-child(n + 5) {
      display: flex;
    }
  }

}
</style>
